<template>
	<div class="p_20 indexBanner">
		<el-dialog :visible.sync="isShow" :close-on-click-modal="false" @close="closeDialog">
			<el-divider></el-divider>
			<el-form :model="form" label-width="80px">
				<el-form-item label="时间">
					<!-- <el-input v-model="form.time" class="w_400"></el-input> -->
					<el-date-picker v-model="form.time" type="month" placeholder="选择时间" value-format="yyyy-MM">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="排序">
					<el-input v-model="form.sort" class="w_400"></el-input>
				</el-form-item>
				<el-form-item label="文本">
					<el-input v-model="form.text" class="w_400"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeDialog">取 消</el-button>
				<el-button type="primary" @click="submit">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				isShow: false,
				form: {
					id:'',
					time: '',
					text: '',
					sort: 0,
				},

				//图片上传
				imageUrl: '',
				// dialogVisible: false,
				// disabled: false
			}
		},
		methods: {
			//提交
			submit() {

				let params = this.form;
				// params.type = 1;
				params.language = this.$store.getters.getLanguage
				console.log(params);
				if (this.form.id) {
					this.edit(params);
				}
				//  else {
				// 	this.add(params);
				// }
			},


			//新增
			add(params) {
				this.axiosGets('index/homepage/banner_add', params, res => {
					if (res.data.code === 0) {
						this.msgSuccess(res.data.message);
						this.$parent.getTableData();
						this.isShow = false;
					}
				})
			},

			//编辑
			edit(params) {
				this.axiosPost('MainIndex/historyEdit', params, res => {
					if (res.data.code === 0) {
						this.msgSuccess(res.data.message);
						this.$parent.getTableData();
						this.isShow = false;
					}
				})
			},


			//图片上传
			handleAvatarSuccess(res) {
				console.log(res);
				// console.log(file);
				//图片id
				this.form.image_id = res.data.id;
				//图片url
				this.imageUrl = this.imgURL + res.data.image_url;
				// this.form.url = res.data.image_url;
				// this.dialogVisible = true;
			},

			//关闭窗口 清空数据
			closeDialog() {
				this.form = {
					id:'',
					time: '',
					text: '',
					sort: 0,
				}
				this.imageUrl = ''
				this.isShow = false;
			}
		}
	}
</script>

<style scoped>

</style>
